﻿using M_Ingredient.API.Application.Command.IngredientCommand;
using M_Ingredient.Repository.Interface;
using MediatR;

namespace M_Ingredient.API.Application.CommandHandler.IngredientCommandHandler
{
    public class IngredientUpdateStateCommandHandler : IRequestHandler<IngredientUpdateStateCommand, int>
    {
        protected readonly IIngredientRepository ingredientRepository;

        public IngredientUpdateStateCommandHandler(IIngredientRepository ingredientRepository)
        {
            this.ingredientRepository = ingredientRepository;
        }

        public async Task<int> Handle(IngredientUpdateStateCommand request, CancellationToken cancellationToken)
        {
            var upSarte = await ingredientRepository.GetModelAsync(request.IngredientId);
            upSarte.State = request.State;
            return await ingredientRepository.UpdateAsync(upSarte);
        }
    }
}
